Top 10k strings from Interactive BASIC Programming (1985)(Eigen Software)(Tape 3 of 3 Side A).tzx in <root> / bin / z80 / software / Sinclair Spectrum Collection TOSEC.exe / Sinclair ZX Spectrum - Utilities & Educational / Sinclair ZX Spectrum - Utilities & Educational - [TZX] (TOSEC-v2007-01-01) /

Back to the directory listing

   4 ;"Press  ENTER"
   2 RANDOMIZE USR 
   2 ;"toggle sound:      SPACE & ENTER"
   2 ;"help:         CAPS SHIFT & ENTER";
   2 ;"forward:    SYMBOL SHIFT & SPACE";
   2 ;"backward:   SYMBOL SHIFT & ENTER";
   2 ;"WARNING: if you enter 
   2 ;"Too long, try again":
   2 ;"Loading, please wait!"
   2 ;"Interactive BASIC Programming";
   2 ;"Copyright 
   2 ;"                   "
   2 ,       it must be followed by            
   2  the Solution, then 
   2  THEN GOTO
   2  1985 Eigen Software"
   2      EIGEN SOFTWARE";
   2           create reality"
   1 total surface area  of cylinder
   1 total number of minutes
   1 total number of hours
   1 then the   delay is so long that you've    effectively turned off the      automatic repeat! Try it now.
   1 statements with 
   1 statement startsrandom numbers off at a set     place in the sequence. This can be of use when dealing with     statistics but we won't considerit futher. Needless to say,
   1 statement at  line 
   1 seconds after                   last minute
   1 s in this   area of memory. Then look at theprogram in this Learning Element
   1 pointer=pointer+32
   1 pointer=256
   1 onwards and   add 
   1 module j  
   1 module i  
   1 minutes=minutes-hours*60
   1 minutes after last hour
   1 line=line/2
   1 later  on.
   1 keyword        (keyphrase?) is used for this.  For example:                      
   1 is   used to make the number         unobtrusive.
   1 ing numbers into ROM has no effect  because ROM cannot be changed.                                  BEWARE!                         Do not 
   1 has two arguments,
   1 gives a flash- ing character square  of normal brightness, blue ink and yellow paper. Try poking this number   into the attribute file.        Since a byte can hold denary    numbers from 0 to 255 there mustbe 256 different attributes.    Write a program that shows all  256 possibilities on the screen at once.
   1 c(pointer+t)=c(pointer+t)+col
   1 c(i)=c(i)+128
   1 c$=c$+"    "
   1 blue paper
   1 b$=b$+"    ":
   1 b$="RED ":
   1 b$="1905":
   1 b$="1234":
   1 area of a cylinder
   1 are rather     technical and usually used with peripheral devices like a       printer.
   1 and fills in a shape.
   1 and change them using 
   1 allows us to do this. The function is  set equal to the attribute byte at row 
   1 add               spaces as padding
   1 a$="green eyes":
   1 a$="forged passport":
   1 a$="curled teeth":
   1 a$="Welcome aboard the Star Ship    Returngift":
   1 a$="Star date 10:56.7":
   1 a$="Personal file: "+n$+" Earthling":
   1 a$="ENTER your name, friend:":
   1 a$="Captain Slog":
   1 Various Positions
   1 This function takes the lengths of the two shortest sides (
   1 The ZX Spectrum {+}    memory map
   1 THEN RETURN 
   1 Spectrum Time
   1 Return from        here for both subroutines! 9000 
   1 RANDOMIZEUSR 
   1 RANDOMIZE 
   1 RANDOMISE USR
   1 Programming
   1 Please note that these routines form part of a program which has yet to be completed.  So, what follows will not 'RUN' sensibly.
   1 PRINT USR 
   1 MODULE J  
   1 MODULE I  
   1 Interactive
   1 In these examples 
   1 In emergency, dial 999
   1 Empire Burlesque
   1 Emotional response
   1 Draw happy part of face8100
   1 Display File
   1 Created with Ramsoft MakeTZX
   1 Cosmic dialogue
   1 Bytes and Pixels
   1 Bytes and Attributes
   1 ;"unlike the";
   1 ;"the 41K)"
   1 ;"takes up by";
   1 ;"special  use";
   1 ;"scale.";
   1 ;"running  BASIC";
   1 ;"previous ones,";
   1 ;"number 56 is displayed"
   1 ;"largest part";
   1 ;"for BASIC";
   1 ;"far the";
   1 ;"by ROM  when";
   1 ;"being typed in";
   1 ;"are NOT to";
   1 ;"You aint seen nothin,"
   1 ;"What is the sum of:";
   1 ;"Variables";
   1 ;"User Defined";
   1 ;"This shows PAPER colours."
   1 ;"These areas,";
   1 ;"The area of the cylinder is:";
   1 ;"The ROM contains a machine code program that cannot be changed.";#0
   1 ;"The Display File will now be    filled up."
   1 ;"The Attribute File will now be  filled wilh random numbers      from 0 to 255."
   1 ;"The Actual";
   1 ;"System Variables"
   1 ;"Reserved RAM";
   1 ;"READ ONLY MEMORY";
   1 ;"RANDOM ACCESS MEMORY"
   1 ;"RAM  for";
   1 ;"Program";
   1 ;"Program Line";
   1 ;"Printer Buffer";
   1 ;"Press any key to pause";
   1 ;"Press SPACE when the";
   1 ;"Please wait, press a key when        the screen is full."
   1 ;"POKE 22992,";i
   1 ;"POKE 16384,";i;
   1 ;"Now we'll add some ink."
   1 ;"Looking at each byte on its own:";
   1 ;"Learning Module J"
   1 ;"Learning Module I"
   1 ;"Just over 7K of the RAM is used by the Spectrum for essential   tasks, the rest is free to BASIC";
   1 ;"Graphics"
   1 ;"Display File";
   1 ;"Complete this well known phrase:";
   1 ;"Command or";
   1 ;"Bit pattern:"
   1 ;"BASIC Programs";#0
   1 ;"BASIC Program";
   1 ;"Attributes";
   1 ;"Areas  for";
   1 ;"Actual BASIC";
   1 ;": ";seconds;" "
   1 ;": ";minutes;" ";
   1 ;"23, 15, and 42"
   1 ;"(say 36K of";
   1 ;"                       "
   1 ;"                                                           "
   1 23692,255 
   1 23676+256*
   1 22527          
   1 16384,a                140
   1 1000000                    110
   1 01000000, 
   1 00000001, 
   1 .Finally, add appropriate 
   1 . Write  these       subroutines now.
   1 . This will reset the      Spectrum without the need to    pull the plug.                  Any other value for 
   1 . Then write themain program.
   1 . Then whenever CAPSSHIFT and BREAK are {BREAK is}  pressed the system will crash.  When you are ready for a rest,  enter 
   1 . Thefirst subroutine will search    from the left of a row of pixels(the 
   1 . The system variables are explained  in Chapter 25 of the  manual {nodescription in the Spectrum +   Manual}. We'll take a closer    look. Some system variables     cannot be changed without       disastrous effects. We will lookat the useful system variables.
   1 .      The second subroutine does the  same as the first but the searchis from the right hand side. Usevariable 
   1 .       Area of circular end = 
   1 .                  Write a subroutine that lives atline
   1 .                      Write a third program that      requests the user to perform    several tasks (forget about     faces). Store this program      between line 
   1 .                              The area of the curved part of  cylinder equals circumference ofthe circular end times 
   1 .          
   1 , use the remainder of a division by 60   for minutes (multiply the       remainder by 60). A loop will   keep generating values.
   1 , then   press some keys. Experiment withdifferent numbers from 0 to 255.
   1 ,     whichever occurs first.
   1 ,     which refer to the pixel at     
   1 ).                 The
   1 ) or no argument at all (e.g.
   1 ) of a right angled triangle   and gives the length of the     hypotenuse (
   1 ) are  in fact quite specific numbers  and they are generated in a     precise order.                  The
   1 (see Learning Module F).    Copy this program into BASIC andrun it:                         
   1 (minutes/60
   1 (d).                    
   1 (a*a+h*h)  
   1 (8) moves the cursor left  one place
   1 ((a-minutes*60
   1 "green ink, green paper at 3,17"
   1 "The memory of the 48K Spectrum  {+} is made up of ROM and RAM:"
   1 "The RAM can be changed. In fact it is changed every time you    press a key!"
   1 "Reserved RAM:";#0
   1 "Radius of circular  end of      cylinder ";r
   1 "RAM for BASIC Programs:";#0
   1 "Length of cylinder ";l
   1 "Enter a word ";c$
   1 "Enter a word ";b$
   1 !)ber to e
   1 !). We will use 
   1  xt=0                   8010 
   1  xr-xl,0    8260
   1  xl=xl+1                8030
   1  would also run the machinecode. 
   1  would     corrupt your program (unless youare instructed otherwise by     commercial software such as     
   1  with decimal numbers!
   1  then thereis nothing to fill on that pixelrow and the next row should be  considered. Otherwise
   1  that draws a glum face and ends with
   1  statement is      crucial: it separates the       subroutines from the main       program. What would happen if   you removed line
   1  statement in  that the computer ignores it    until the function is used. The function is used as any other   function would be but the
   1  statement can be     placed anywhere in the program. It is like a 
   1  row) until an ink        coloured pixel is found. It     returns with the x-coordinate ofthis pixel in variable 
   1  prints 243. This first   byte (at address 0) is in ROM   and cannot be changed: it is    always 243. If you
   1  means reset the random number system to a       specific point. The random      numbers (created with 
   1  is turned on.                                            the square is flashing
   1  is turned           off: if it is 1 then            
   1  is theend of the subroutine so your   Spectrum will go back to the    point after the call.           List the program in this        Learning Element and, before    running it, work out what it    will do. CLOSE YOUR EYES WHEN   PASSING THE HINTS!!!!!
   1  is set equal to a   number after the  machine code  has run. This number is usually of no use and so 
   1  is just an      unobtrusive way of running      machine code.
   1  is ink       colour, 0 if it is paper colour.We shall now write a subroutine that colours in any closed      shape. A closed shape is a shapethat has a continuous perimeter (e.g. a circle, square,         triangle).
   1  is an addressin ROM or RAM) is used to run   machine code programs. The      important part of this statementis 
   1  is a string argument and the result  is a number.
   1  is a numerical argument and   the result is a number. 
   1  is a numerical   argument and the result is a    string.                         It is possible to have functionswith more than one argument     (e.g.
   1  into the byteat address
   1  in the  wrong places the system may     crash, i.e. the Spectrum no     longer responds to the keyboard in a sensible way, if at all.   A crash doesn't cause any damageto the hardware: you should     reset the machine if it happens.
   1  i                     9030 
   1  gives 1 if   the pixel at
   1  function but  we'd have to be desperate to useit! Perhaps you can think of a  quicker method.
   1  except when 
   1  contains 255 or
   1  can be 0 or 1
   1  bytes ataddresses greater than 16383    then you could get any number   from 0 to 255 since this is RAM and can change.
   1  bit is 1           but steady if the               
   1  bit is 0.                                       
   1  as the last line.    Write a second program from line
   1  as its result.
   1  as its argument and  gives the area of a circle of   radius
   1  are used with ZX Microdrives. If youbuy a ZX Interface 1 full       instructions will accompany it.
   1  are really  machine code instructions that  can be used from BASIC.         All of these instructions are   unlikely to be of much use to   most BASIC programmers.
   1  are called arguments.     
   1  and line 
   1  and its length is
   1  and is used seven     times in the main program (whereyou see 
   1  and column
   1  and   end at the first ink pixel or   the end of the row 
   1  after each task.
   1  addresses other thanthose in the range 16384 to     23551, yet. If you 
   1  a=(65636*
   1  a$          9010 
   1  a                      130
   1  Your Spectrum provides you  with lots of functions:         e.g. 
   1  You should have run the     program in this Learning Elementto check if you're right. Noticethat the
   1  You might find that this    Learning Module is rather       technical. It probably is! If   you cannot understand some partsdon't worry, it's not essential BASIC.                          The memory of your Spectrum is  in two parts: 16K of Read Only  Memory (ROM) and 48K of Random  Access Memory (RAM).            ROM contains a complex program  written by Sinclair Research Ltdand cannot be changed in any wayRAM contents can be changed; it stores data for the TV picture, your programs & info for the ROMAll this memory is made up of   boxes that can hold integers    from 0 to 255. These are called bytes. 1K means 1024 bytes so   the 64K of memory (ROM and RAM) is made up of 65536 bytes.
   1  You can think of the       subroutines as being programs intheir own right. Write a programthat draws a smiling face, storeit from line
   1  Write a program to discover how the attribute file is       organized. You will probably be able to put this to good use    some time.
   1  Write a program that        requests the user to perform a  number of tasks. If a task is   carried out correctly then a    smiling face is drawn.          A glum face is drawn for an     incorrect response. Write one   subroutine for the smiling face and one for the glum face.
   1  With 65536 bytes (numbers   between 0 and 255) it would be  easy to get mixed up.Fortunatelythere is a simple order given tothese bytes. Each byte is given a number that tells us the posi-tion of the byte in memory.     These numbers are called        addresses.                      0 is the address of the first   byte, 1 is the address of the   second byte, 65535 is the       address of the last byte.  So   there are 65536 bytes. All byteshave a precise order.The addressof a byte is simply a number    that tells us where it lives.   Run the program in this LearningElement.
   1  We will now mention some of the more obscure keywords.      
   1  We can tell the Spectrum to expect a binary number by using 
   1  We can discover the numbers in each box by using 
   1  We can change the RAM bytes by using
   1  User-defined functions have to be defined (gripping stuff,  eh!). The
   1  Use a loop.
   1  Use a loop with control    variable ranging from 0 to 255.
   1  To colour in (or fill) a    closed shape we scan each       horizontal row of pixels. First write two subroutines and store them at lines
   1  This fill subroutine is veryslow indeed. It illustrates a   use for the 
   1  There is a Spectrum functionwe have yet to use: 
   1  There are many more system  variables but they are either ofno use or too complicated to    understand without learning muchmore about software.
   1  The system variable at      address 23561 stores the length of time for which a key must be held down before it repeats.    This byte usually contains 35   and there is probably little    point in reducing it. If you    enter 
   1  The surface area of a      cylinder with closed ends is    equal to the surface area of thecurved part plus the surface    areas of the two circles that   form the ends.                  Suppose the radius of the       cylinder is
   1  The subroutine starts at   line
   1  The subroutine prints
   1  The screen is stored in an  odd sort of way, which is best  seen by looking at the loading  of the title screen of a game.  Run this program to simulate theeffect:                                 
   1  The screen is arranged in   this way for technical reasons. We will not be dealing futher   with the screen.
   1  The only quick way to fill shapes is in machine code. We   will not be dealing with machinecode.
   1  The Spectrum allows you to  have your own functions. If the result of a function is a numberthe function can be given any   single letter (followed by $ fora string result) as a name.     The arguments have to be single letters (followed by $ for a    string argument) and placed in  brackets after the function name(the brackets must be present,  even if there are no arguments!)Examples will make this clear.
   1  THEN PRINT
   1  Subroutines can be "nested",i.e. a subroutine can call a    second subroutine (which can    call a third and so on!). It is a good idea to keep a library ofgood subroutines and functions. These can be kept on paper so   they can be typed in as requiredor stored on tape so they can be
   1  Subroutines are used to savememory, make programs easier to read and reduce numb fingers.
   1  RANDOMIZE USR
   1  RANDOMIZE
   1  PRINTPEEK
   1  Only ever use 
   1  Now for the system variablesThese are bytes set aside for   use by the ROM program. We can  look at these numbers using
   1  Now for the attribute file, which is quite interesting.     Remember to think of the screen as being divided into 24 rows of32 character positions. Each    character position can have its own ink colour and its own papercolour. A byte in the attribute file corresponds to the colours in one character square.
   1  Now for a brief mention     about machine code. Machine codeprograms are completly differentfrom BASIC programs. They are   not easy to write but can do    clever things very speedily.    Most commercially produced      programs for your Spectrum are  written in machine code.        
   1  Modify your clock program sothat it accepts a starting time as input and uses this to set   bytes at 23672, 23673 and 23674.So you could start the clock offat the right time.
   1  It is probably  easier to   read a program that keeps its   function definitions at the end of the list. Define a function  that has 
   1  Increase the address from  22528 to 22528+255.
   1  In using the screen it may  be useful to test for the attri-butes present.
   1  In this Learning Module you will learn about subroutines andfunctions.                      Programs very often contain     groups of three or more lines ofBASIC repeated at several pointsin the listing. It seems daft totype out the same lines many    times!
   1  In order to understand how  the numbers 0 to 255 have the   effect that  they do have on thescreen we must think in terms ofbinary numbers.                 A binary digit (bit) can be 0 or1. Counting in binary is easy,  compare these:                     denary     binary                 0         000                   1         001                   2         010                   3         011                   4         100                   5         101                   6         110                   7         111              3 bits can represent the denary (decimal) numbers 0 to 7. 8 bitscan represent the denary numbers0 to 255. Each byte is 8 bits   long!
   1  If you poke addresses       between 16384 and 22527 then thetelevision picture is changed.  Experiment with
   1  Having mentioned the        existence of machine code there is not much you can do with    
   1  Having acquired 
   1  Fortunately BASIC can help  us, with subroutines. The       repeated lines are collected    together at the end of the      program and then called when    they're needed.                   
   1  For the first subroutine   start the search at 
   1  For each row scanned, if 
   1  Finally, 23692 contains a   number which is one more than   the number of lines that can be printed before SCROLL?  appears.Enter this line:                   
   1  Each byte of the attribute  file looks like this:           
   1  Draw rest of face      8200
   1  Draw glum part of face 9100
   1  Consider the subroutines    from the last problem. They bothdraw faces that have much in    common. So we could have writtenthe program like this:          
   1  Circumference:                    
   1  By poking the right numbers into addresses 16384 through to 16415, can you make a dot move  across the screen?
   1  Address 16384 corresponds tothe first eight horizontal      pixels on the top left of the   screen. Each bit of the byte at 16384 is in direct corresponden-ce with those eight pixels. If  the bit is 0 then the paper     colour is shown: if it is 1 thenthe ink colour is shown. Write aprogram that displays all the   possible pixel patterns for the byte at 16384.
   1  A user-defined function can use a second user-defined       function. Define a function thatgives the surface area of a     cylinder with closed ends. Make it use a function for the area  of a circle and another functionfor the circumference of a      circle.
   1  8260    8250 
   1  8100                 8240
   1  8000                 8220
   1  8                120
   1  23692,255: 
   1  23674+256*
   1  23672, 23673 and 23676      contain the Spectrum clock      
   1  23672)/50
   1  23659,0. Your        Spectrum will try to print O.K. on the bottom of the screen (hav-ing carried out your instruct- ion) but crashes instead!
   1  23659 stores the number of  lines in the lower part of the  screen. If you poke 0 into this system variable then the system will crash when it next producesan  error report. DON'T POKE    THIS YET!                       23659 provides us with a way of protecting programs. If you     don't want someone to list your program then make the first line
   1  23609,120
   1  23562 is quite useful. It   stores the length of time       between successive repeats of a key held down, once auto-repeat has started. Try
   1  23561,255 
   1  175             8210
   1  10110001 
   1  1,1                                 9020 
   1  (xl,y)=1 
   1  (notice the    comma, it's important). 
   1    would print 5.
   1    to the colours above  
   1    one character at a time.
   1    if the 
   1    and watch the cursor zip around.23609 stores the length of clickthat is heard when you press a  key. Try 
   1    INFIDELS
   1    Circumference of circle = 2x
   1     puts the number 
   1     keyword appears before the func-tion name. So
   1      three bits for 
   1      RANDOMIZE USR
   1       circumference of a circle
   1       Area of circle:                        
   1         (This function is a bit like
   1          three bits for 
   1          three bits can repre-           sent numbers from 0 to
   1          the keys 0 to 7.                                                if the 
   1          7 and these correspond
   1             NEXT
   1             150 
   1                area of circle
   1                  gives the time in seconds since the computer was switched on.   You can reset the clock by      poking 0 into these three bytes.Write a program that prints the 'Spectrum time' on the screen inhours, mins and seconds.
   1                   This is a subroutine. It is     called (told to run) with 
   1                   Draw a circle or some other     closed shape and enter as a     direct command
   1                    8020
   1                        The following technique should  only be used in dire            circumstances and then only withextreme care!                      
   1                             in order to turn off the SCROLL?                                                 Enter 
   1                                 x
   1